package com.yh.csx.demo.controller;

import com.yh.csx.bsf.redis.annotation.RedisCache;
import com.yh.csx.demo.model.User;
import com.yh.csx.demo.model.response.CommonResponse;
import com.yh.csx.demo.provider.ErrorProvider;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api("错误测试")
@RestController
public class ErrorController implements ErrorProvider {

    @GetMapping("/callBiz")
    public CommonResponse<String> callBiz() {
        return CommonResponse.success("错误了");
    }
	@ApiOperation("错误报警测试")
    @GetMapping("/callError")
    public CommonResponse<User> callError(long userId) {
        if (userId != 10) {
             log.error("你大爷的",new IllegalArgumentException("错误了"));
        }
        return CommonResponse.success();
    }

    @GetMapping("/callArray")
    @RedisCache(timeout = 60)
    public String[] callArray(int length) {
        System.out.println("call");
        if (length != 10) {
            throw new IllegalArgumentException("length != 10");
        }
        return new String[length];
    }

}
